<?php
/**
 * Created by JetBrains PhpStorm.
 * User: scala
 * Date: 12-10-23
 * Time: 上午10:41
 * To change this template use File | Settings | File Templates.
 */
class NewsAction extends Action
{

    function index(){
        $news=M("News");
        import("ORG.Util.Page");// 导入分页类
        $count=$news->count();
        $Page= new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfigArray(array('header'=>'条新闻','prev'=>'<input type="button" value="<<">','next'=>'<input type="button" value=">>">','first'=>'首页','last'=>'尾页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页   %first% %prePage% %upPage%   <span style="color: red;">%linkPage%</span>   %downPage% %nextPage% %end%'));
        $show=$Page->show();//分页显示输出
        $newsList=$news->limit($Page->firstRow.",".$Page->listRows)->order("id desc")->select();
        $this->assign("newsList",$newsList);
        $this->assign('page',$show);// 赋值分页输出
		
		$article=M("StaffArticle");
		$user=M("User");
		$list=$article->limit('0,3')->order("createtime desc")->select();
        $userList=$user->select();
		$this->assign("list",$list);
        $this->assign("userList",$userList);
        $this->display();
    }

    function details(){
		$article=M("StaffArticle");
		$user=M("User");
		$list=$article->limit('0,3')->order("createtime desc")->select();
        $userList=$user->select();
		$this->assign("list",$list);
        $this->assign("userList",$userList);
	
        $news=M("News");
        if(isset($_GET["id"])){
            if($newsObj=$news->where("id=".$_GET["id"])->find()){
                $this->assign("news",$newsObj);
                $this->display();
            }else{
                $this->error("您要查看的新闻信息已经不存在!");
            }
        }else{
            $this->error("系统错误，请联系我们!");
        }

    }

}
